<#--字段声明-->
<#--项目基础包名-->
<#assign AppPackageName = "${cfg.AppPackage}">
<#assign BaseMoudleName = "${package.ModuleName}">
<#assign ModulePackageName = "${cfg.ModulePackage}">
<#assign EntityPrefixName = "${entity?substring(0,entity?length-cfg.EntitySuffix?length)}">
<#--DO-->
<#assign DoName = "${entity}">
<#assign DoPackage = "${package.Entity}">
<#--BO-->
<#assign BoName = "${EntityPrefixName}${cfg.BoSuffix}">
<#assign BoPackage = "${ModulePackageName}.${cfg.BoPackageName}">
<#--DTO-->
<#assign DtoName = "${EntityPrefixName}${cfg.DtoSuffix}">
<#assign DtoPackage = "${ModulePackageName}.${cfg.DtoPackageName}">
<#--Convert-->
<#assign ConvertName = "${EntityPrefixName}${cfg.ConvertSuffix}">
<#assign ConvertPackage = "${ModulePackageName}.${cfg.ConvertPackageName}">
<#--正文-->
package ${package.ServiceImpl};

<#--mybatis-plus自带-->
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

<#--框架依赖，一般不变-->
import ${AppPackageName}.common.core.vo.PageData;

<#--模块内部依赖-->
import ${BoPackage}.${BoName};
import ${DtoPackage}.${DtoName};
import ${ConvertPackage}.${ConvertName};

import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import org.springframework.stereotype.Service;

<#--JDK自带-->
import java.util.ArrayList;
import java.util.List;

/**
 * ${table.comment!} 服务实现类
 *
 * @author ${author}
 * @since ${date}
 */
@Service
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {

}
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {

    @Override
    public ${BoName} readById(Long id) {
        return ${ConvertName}.INSTANCE.do2bo(getById(id));
    }

    @Override
    public List<${BoName}> readByIds(List<Long> ids) {
        return ${ConvertName}.INSTANCE.do2bo(new ArrayList<>(listByIds(ids)));
    }

    @Override
    public List<${BoName}> readList(${DtoName} condition) {
        return ${ConvertName}.INSTANCE.do2bo(list(Wrappers.lambdaQuery(${ConvertName}.INSTANCE.dto2do(condition))));
    }

    @Override
    public PageData<${BoName}> readPage(Long pageNum, Long pageSize, ${DtoName} condition) {
        IPage<${DoName}> page = page(new Page<>(pageNum, pageSize), Wrappers.lambdaQuery(${ConvertName}.INSTANCE.dto2do(condition)));
        return PageData.build(page, ${ConvertName}.INSTANCE.do2bo(page.getRecords()));
    }

    @Override
    public Long createOne(${DtoName} dto) {
        ${DoName} domain = ${ConvertName}.INSTANCE.dto2do(dto);
        return save(domain) ? domain.getId() : null;
    }

    @Override
    public Long updateOne(Long id, ${DtoName} dto) {
        return updateById(${ConvertName}.INSTANCE.dto2do(dto).setId(id)) ? id : null;
    }

    @Override
    public Long deleteById(Long id) {
        return removeById(id) ? id : null;
    }

    @Override
    public List<Long> deleteByIds(List<Long> ids) {
        return removeByIds(ids) ? ids : null;
    }

}
</#if>
